package com.example.controller;

import com.example.domain.GroupMember;
import com.example.service.IGroupMemberService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/system/group-member")
public class GroupMemberController extends BaseController {

    @Autowired
    private IGroupMemberService groupMemberService;

    @GetMapping("/list/{groupId}")
    public AjaxResult list(@PathVariable Long groupId) {
        List<GroupMember> list = groupMemberService.selectGroupMemberListByGroupId(groupId);
        return AjaxResult.success(list);
    }

    @PostMapping
    public AjaxResult add(@RequestBody GroupMember groupMember) {
        return toAjax(groupMemberService.insertGroupMember(groupMember));
    }

    @PutMapping
    public AjaxResult edit(@RequestBody GroupMember groupMember) {
        return toAjax(groupMemberService.updateGroupMember(groupMember));
    }

    @DeleteMapping("/{memberId}")
    public AjaxResult remove(@PathVariable Long memberId) {
        return toAjax(groupMemberService.deleteGroupMemberById(memberId));
    }

    @DeleteMapping("/by-group-id/{groupId}")
    public AjaxResult removeByGroupId(@PathVariable Long groupId) {
        return toAjax(groupMemberService.deleteGroupMembersByGroupId(groupId));
    }
}